<?php

/**
 * ogloszenia actions.
 *
 * @package    portal
 * @subpackage ogloszenia
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class ogloszeniaActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
      $response = $this->getResponse();

      $c = new Criteria();
      $pager = new sfPropelPager('Ogloszenie', 2);
      $c->addAscendingOrderByColumn(OgloszeniePeer::ID);
      $pager->setCriteria($c);
      $pager->setPage($this->getRequestParameter('page', 1));
      $pager->init();
    $this->pager=$pager;
      //$this->ogloszenie_list = OgloszeniePeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
      $this->poddziedziny = OczekujePeer::getIdPoddziedzina($request->getParameter('id'));
    $this->ogloszenie = OgloszeniePeer::retrieveByPk($request->getParameter('id'));
    
      $this->forward404Unless($this->ogloszenie);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new OgloszenieForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new OgloszenieForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($ogloszenie = OgloszeniePeer::retrieveByPk($request->getParameter('id')), sprintf('Object ogloszenie does not exist (%s).', $request->getParameter('id')));
    $this->form = new OgloszenieForm($ogloszenie);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($ogloszenie = OgloszeniePeer::retrieveByPk($request->getParameter('id')), sprintf('Object ogloszenie does not exist (%s).', $request->getParameter('id')));
    $this->form = new OgloszenieForm($ogloszenie);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($ogloszenie = OgloszeniePeer::retrieveByPk($request->getParameter('id')), sprintf('Object ogloszenie does not exist (%s).', $request->getParameter('id')));
    $ogloszenie->delete();

    $this->redirect('ogloszenia/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $ogloszenie = $form->save();

      $this->redirect('ogloszenia/edit?id='.$ogloszenie->getId());
    }
  }
}
